Page({
  data: {
    salary: 0,
    assets: 0,
    debts: 0,
    height: 0,
    weight: 0,
    exPartners: 0,
    degree: '',
    job: '',
    local: '',
    appearance: '',
    degreeOptions: ['本科', '硕士及以上', '专科以下'],
    jobOptions: ['否', '是'],
    localOptions: ['否', '是'],
    appearanceOptions: ['否', '是'],
    calculatedResult: null
  },

  onInputChange: function (e) {
    const field = e.currentTarget.dataset.field;
    this.setData({
      [field]: parseFloat(e.detail.value) || 0
    });
  },

  onDegreeChange: function (e) {
    const degree = this.data.degreeOptions[e.detail.value];
    this.setData({
      degree
    });
  },

  onJobChange: function (e) {
    const job = this.data.jobOptions[e.detail.value];
    this.setData({
      job
    });
  },

  onLocalChange: function (e) {
    const local = this.data.localOptions[e.detail.value];
    this.setData({
      local
    });
  },

  onAppearanceChange: function (e) {
    const appearance = this.data.appearanceOptions[e.detail.value];
    this.setData({
      appearance
    });
  },

  handleSubmit: function () {
    let { salary, assets, debts, degree, height, weight, exPartners, job, local, appearance } = this.data;

    // 基本计算
    let bridePrice = salary;

    // 资产与负债
    bridePrice += Math.floor(assets / 10);
    bridePrice -= Math.floor(debts / 10);

    // 学历
    if (degree === '硕士及以上') bridePrice += 2;
    else if (degree === '本科') bridePrice += 1;
    else if (degree === '专科以下') bridePrice -= 1;

    // 身高与体重
    if (height >= 170) bridePrice += 2;
    else if (height >= 165) bridePrice += 1;

    if (weight > 105) bridePrice -= Math.floor((weight - 105) / 5);

    // 公务员/事业单位/国企
    if (job === '是') bridePrice += 1;

    // 本地
    if (local === '是') bridePrice += 2;

    // 颜值逆天
    if (appearance === '是') bridePrice += 1;

    // 前任数量
    bridePrice -= exPartners;

    // 显示计算结果
    this.setData({
      calculatedResult: bridePrice
    });
  }
});
